
package com.example.softwareconfigurationcoursedesign.Admin;

import java.math.BigInteger;
import java.security.MessageDigest;

public class MD5Encryption {

    public static String encryptStringToMD5(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] messageDigest = md.digest(input.getBytes());
            BigInteger no = new BigInteger(1, messageDigest);
            StringBuilder SB = new StringBuilder(no.toString(16));
            while (SB.length() < 32) {
                SB.insert(0, "0");
            }
            return SB.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        String input = "MD5";
        String encrypted = encryptStringToMD5(input);
        System.out.println("MD5 加密后：" + encrypted);
    }
}
